package com.data;

import javax.swing.*;
import java.util.Random;

public class TrainerData {
    //属性
    private int op1=0;
    private int op2=0;
    private String opLabel="+";
    private String ans ="";

    //方法
    public int getOp1() {
        return op1;
    }

    public void setOp1(int op1) {
        this.op1 = op1;
    }

    public int getOp2() {
        return op2;
    }

    public void setOp2(int op2) {
        this.op2 = op2;
    }

    public String getOpLabel() {
        return opLabel;
    }

    public void setOpLabel(String opLabel) {
        this.opLabel = opLabel;
    }

    public void setAns(String ans){
        this.ans=ans;
    }

    public String getAns() {
        return ans;
    }

    public void setTrainerData(String patten) {
        if (patten.equals("加减法")) {
            if (new Random().nextInt(100) % 2 == 0) {
                opLabel = "+";
            } else {
                opLabel = "-";
            }
        }else if(patten.equals("加法")){
            opLabel = "+";
        }else{
            opLabel = "-";
        }
        op1 = new Random().nextInt(100);
        op2 = new Random().nextInt(100);
        if (opLabel.equals("-") && op2 > op1) {
            int tmp = op1;
            op1 = op2;
            op2 = tmp;
        }
    }

    /**
     * 判断这个式子是否正确
     * @return 题目正确返回true，否则返回false
     */
    public boolean judgeCorrect(){
        try {
            if (opLabel.equals("+") && Integer.parseInt(ans)==op1+op2){
                return true;
            }
            return opLabel.equals("-") && Integer.parseInt(ans) == op1 - op2;
        }catch (Exception e){
            return false;
        }

    }
}
